<?php

	class Default_Form_Common extends Zend_Form
	{

	    public function init()
	    {

	        $this->setDecorators(array(
	            'FormElements',
	            'Fieldset',
	            array('HtmlTag', array('tag' => 'dl', 'class' => '')),
	            array('Description', array('placement' => 'prepend', 'class' => 'resMsgBox error')),
	            //array('Errors', array('placement' => 'append', 'class' => 'failureText')),
	            'Form'
	        ));
//	        $this->setElementDecorators(array(
//	           'ViewHelper',
//	            'Label', array('requiredSuffix' => ' *','tag' => 'dt','escape' => false),
//			));
	        //$this->setElementDecorators()->requiredSuffix(' *');


   		//$request = $this->getRequest();
			$referer = $this->createElement('hidden', 'referer');
			$this->addElement($referer);

	    }


	    public function _addCaptcha($type = '')
	    {
	    	$siteConfig = Zend_Registry::get('siteConfig');

	    	switch ($type) {

	    		default:
	    		case '';
	    		case null;
	    		case 'image';



						$this->addElement('captcha', 'captcha', array(
						    //'label' => "verification-code",
						    'captcha' => 'Image',
						    'captchaOptions' => array(
						        'captcha' => 'Image',
						        'imgUrl' => $siteConfig->captcha->image->url,
						        'imgdir' => $siteConfig->captcha->store->directory,
						        'font' => $siteConfig->captcha->fonts->directory . '/verdanab.ttf',
						        'wordLen' => 4,
						        'timeout' => 300,
						        'height' => '50px',
						        'width' => '200px',
						    ),
				            //'decorators' => $decorators

						));
                        $this->getElement('captcha')->setLabel('verification-code');//setLabel fonksiyonu poedit translate fonksiyonlari arasina alindi..
						//$this->captcha->setDecorators($decorators);

	    			break;

	    		case 'dump';

						$this->addElement('captcha','captcha',
							array(
								//'label' => 'Please enter the 4 letters displayed below:',
								'name' => 'captcha',
								'required' => true,
								'captcha' =>
									array(
										'captcha' => 'dumb',
										'wordLen' => 4,
										'timeOut' => 5
									)
							)
						);
                        $this->getElement('captcha')->setLabel('Please enter the 4 letters displayed below');//setLabel fonksiyonu poedit translate fonksiyonlari arasina alindi..

	    			break;

	    		case 'figlet';

			         	$this->addElement('captcha', 'captcha', array(
						    //'label' => "Code Verification",
						    'captcha' => 'Figlet',
						    'captchaOptions' => array(
						        'captcha' => 'Figlet',
						        'wordLen' => 4,
						        'timeout' => 300,
						        'font' => $siteConfig->figlet->fonts->directory . '/alligator2.flf',
						    ),
						));
                         $this->getElement('captcha')->setLabel('verification-code');//setLabel fonksiyonu poedit translate fonksiyonlari arasina alindi..

	    			break;
	    		case 'reCaptcha';

	    			break;
	    	}

	    }

	    public function _addCRSF()
	    {
	    	$this->addElement('hash', 'crsf_token', array('salt' => 'unique'));//->getElement('crsf_token')->setLabel('crsf-token');
	    }

	    public function _addSubmit()
	    {
			$submit = $this->createElement('submit', 'submit');
			$submit->setLabel('buttons:submit')
	               	->setRequired(false)
	               	->setAttrib('class', 'fancyButtons')
           	;

			$this->addElement($submit);
	        /*
	        $this->addElement('submit', 'submit', array(
	            'required' => false,
	            'ignore'   => true,
	            'label'    => 'Submit',
	        ));
			*/
	        //add filters automatically
	        $this->_addFilters();
	    }

	    public function _addFilters($filters=array())
	    {
	    	if (empty($filters)) {
				//$filters = array('StringTrim', 'HtmlEntities');
//				$htmlEntitiesFilter = new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES));

//				echo $htmlEntitiesFilter->filter("lorem ips'um üntela");
//				echo '<br />';
//				echo htmlentities("lorem ips'um üntela", ENT_QUOTES, 'utf-8');
//				echo '<br />';
//				echo htmlspecialchars("lorem ips'um üntela", ENT_QUOTES);
//
//				exit;
				$filters = array(
					'StringTrim',
//					$htmlEntitiesFilter
					);
				//$filters = array('StringTrim');
	    	}
	    	$this->setElementFilters($filters);
	    }

	}
